package com.techme.jetpack.navigation

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.example.jetpack_android_online.R
import com.example.jetpack_android_online.databinding.LayoutFragmentCategoryBinding

class CategoryFragment : BaseFragment() {
    private lateinit var categoryBinding: LayoutFragmentCategoryBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.e("TAG", "CategoryFragment onCreate: $savedInstanceState" )
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        categoryBinding = LayoutFragmentCategoryBinding.inflate(inflater, container, false)
        return categoryBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?)
    {
        super.onViewCreated(view, savedInstanceState)
        categoryBinding.navigateToTagsFragment.setOnClickListener {
            findNavController().navigate(R.id.tags_fragment)
            //演示navigateUp
//            findNavController().navigateUp()
        }

        categoryBinding.getStackTopFragment.setOnClickListener {
            val navController = findNavController()
            val currentDestination = navController.currentDestination
            Log.e("TAG", "CategoryFragment currentFragment: $currentDestination" )
        }

    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putString("outState", "开始保存SaveInstanceState")
    }
}